package com.spotalog.shared.model.query;

import java.util.Map;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;

public enum Filter {
	LT("<"), LTE("<="), EQ("="), GT(">"), GTE(">="), IN("in"), NOT("!=");

	private static final Map<String, Filter> MAP = Maps.newHashMap();
	static {
		for (Filter filter : Filter.values()) {
			MAP.put(filter.name, filter);
		}
	}
	private final String name;

	private Filter(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return this.name;
	}

	public String toCondition(Property property) {
		return property.getPropertyName() + " " + this.name;
	}

	public static Filter fromString(String name) {
		return MAP.get(Strings.nullToEmpty(name.toLowerCase().trim()));
	}
}
